package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.itheima.mapper.SalaryMapper;

import com.itheima.pojo.Result;
import com.itheima.pojo.Salary;

import com.itheima.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class SalaryServiceImpl extends ServiceImpl<SalaryMapper, Salary> implements SalaryService {

    @Autowired
    private SalaryMapper salaryMapper;

    @Override
    public Result<Page> selectPage(Page page, String keyWord) {
        // 创建LambdaQueryWrapper来构造查询条件
        LambdaQueryWrapper<Salary> salaryLambdaQueryWrapper = new LambdaQueryWrapper<>();

        // 进行模糊查询，查询条件是员工姓名
        if (StringUtils.isNotBlank(keyWord)) {
            salaryLambdaQueryWrapper.like(Salary::getEmployeeName, keyWord);
        }
        // 调用Mapper的selectPage方法进行分页查询
        Page page1 = salaryMapper.selectPage(page, salaryLambdaQueryWrapper);
        return Result.success(page1);
    }
    @Override
    public Result<Page> selectPage1(Page page, Integer employeeId, String month) {
        // 创建LambdaQueryWrapper来构造查询条件
        LambdaQueryWrapper<Salary> salaryLambdaQueryWrapper = new LambdaQueryWrapper<>();

        // 根据Id进行查询（假设Id为员工的唯一标识符）
        if (employeeId != null) {
            salaryLambdaQueryWrapper.eq(Salary::getEmployeeId, employeeId);
        }

        // 根据Month进行查询（假设是某个月的工资记录）
        if (StringUtils.isNotBlank(month)) {
            salaryLambdaQueryWrapper.eq(Salary::getMonth, month);
        }

        // 调用Mapper的selectPage方法进行分页查询
        Page<Salary> page1 = salaryMapper.selectPage(page, salaryLambdaQueryWrapper);

        // 返回查询结果
        return Result.success(page1);
    }

}
